package com.srd.phone.bean;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class NoticeInfo implements Serializable {


    /**
     * id : 1
     * title : 发给他还是让他
     * subtitle : 谁的歌
     * author : 是的
     * source : 是的
     * cuse : 0
     * ctime : /Date(1433779200000)/
     * ctime_Str : 2015/6/9 0:00:00
     * sort : 1
     * stat : 2
     * cid : 8
     * cnm : 投诉中心
     */

    public int id;
    public String title;
    public String subtitle;
    public String content;
    public String author;
    public String source;
    public int cuse;
    public String ctime;
    public String ctime_Str;
    public int sort;
    public int stat;
    public int cid;
    public String cnm;

    public String data;

    public static List<NoticeInfo> parser(String json) {
        List<NoticeInfo> list = new ArrayList<>();
        try {
            JSONObject jo = new JSONObject(json);
            JSONArray jsonArray = jo.optJSONArray("data");
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                NoticeInfo info = new NoticeInfo();
                info.id = jsonObject.optInt("id");
                info.title = jsonObject.optString("title");
                info.subtitle = jsonObject.optString("subtitle");
                info.ctime_Str = jsonObject.optString("ctime_Str");
                list.add(info);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    public static NoticeInfo parserInfo(String json) {
        NoticeInfo noticeInfo = new NoticeInfo();
        try {
            JSONObject jsonObject = new JSONObject(json);
            noticeInfo.data = jsonObject.optString("data");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return noticeInfo;
    }

}
